<template>
  <div>
    <el-form :model="formData" :rules="rules">
      <el-form-item label="用户名" prop="username">
        <el-input v-model="formData.username" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="formData.password" />
      </el-form-item>
      <el-form-item label="重新输入密码" prop="checkPass">
        <el-input v-model="formData.checkPass" />
      </el-form-item>
      <el-button>登录</el-button>
    </el-form>
  </div>
</template>
<script>
import { getProfile } from '@/api/user.js'
export default {
  name: '',
  components: {},
  props: {
  },
  data() {
    // 定义一个自定义校验函数， 交给rules
    // 每当当失去焦点的时候，这个函数就会被调用
    const validPassword = (rule, val, callback) => {
      // 自带三个参数, rule 当前使用规则， val 当前用户输入的值， calback 放行回调函数
      // 1， 写出判断逻辑输出 true / false
      const isVal = val === this.formData.password
      // 2， 根据解构调出回调
      if (isVal) {
        callback()
      } else {
        callback(new Error('两次密码必须相同'))
      }
    }
    return {
      formData: {
        username: '',
        password: '',
        checkPass: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { pattern: /^1[3-9][0-9]{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 12, message: '密码长度为6-12位', trigger: 'blur' }
        ],
        checkPass: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 12, message: '密码长度为6-12位', trigger: 'blur' },
          { validator: validPassword, trigger: 'blur' }
        ]
      }
    }
  },
  computed: {},
  watch: {},
  async  created() {
    const res = await getProfile()
    console.log(65, res)
  },
  mounted() {

  },
  methods: {
  }
}
</script>
<style scoped lang='less'>
</style>
